package com.quotes.dates;

import java.text.SimpleDateFormat;
import java.util.*;

public class TimeRange
{
	Calendar calendar = Calendar.getInstance();
	private Date start;
	private Date end;
	
	public TimeRange(Date start, Date end) {
		this.start = start;
		this.end = end;
	}
	
	public void shift(int field, int amount) {
		calendar.setTime(this.start);
		calendar.add(field, amount);
		calendar.setTime(this.end);
		calendar.add(field, amount);
	}
	
	public Date getStart() {
		return start;
	}
	
	public Date getEnd() {
		return end;
	}
	
	public String toString() {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		return dateFormat.format(this.getStart()) + " -- " + dateFormat.format(this.getEnd());
	}
	
	public boolean isIn(Date date) {
		return (date != null && date.compareTo(start) >= 0 && date.compareTo(end) <= 0);
	}
}
